package com.huawei.hianalytics.ab.fg;

import android.content.Context;
import com.huawei.hianalytics.ab.bc.ef.ab;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.json.JSONException;
import org.json.JSONObject;

public final class bc {
    private static bc ab = null;
    private Context bc;
    private final Object cd = new Object();

    private bc() {
    }

    public static bc ab() {
        if (ab == null) {
            bc();
        }
        return ab;
    }

    private JSONObject ab(Map<String, String> map) {
        JSONObject jSONObject = new JSONObject();
        if (map != null) {
            try {
                for (Entry entry : map.entrySet()) {
                    jSONObject.put((String) entry.getKey(), entry.getValue());
                }
            } catch (JSONException e) {
                ab.de("HiAnalyticsEventManager", "Exception occured when transferring bundle to json");
            }
        }
        return jSONObject;
    }

    private static synchronized void bc() {
        synchronized (bc.class) {
            if (ab == null) {
                ab = new bc();
            }
        }
    }

    public void ab(Context context) {
        synchronized (this.cd) {
            if (this.bc != null) {
                return;
            }
            this.bc = context;
            com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().ab(context);
        }
    }

    public void ab(String str, int i) {
        com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().ab(str, i);
    }

    public void ab(String str, int i, String str2, LinkedHashMap<String, String> linkedHashMap) {
        com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().ab(str, i, str2, ab((Map) linkedHashMap));
    }

    public void ab(String str, Context context) {
        com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().ab(str, context.getClass().getCanonicalName(), new JSONObject());
    }

    public void ab(String str, Context context, String str2, String str3) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("_constants", str3);
            com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().ab(str, 0, str2, jSONObject);
        } catch (JSONException e) {
            ab.cd("HiAnalyticsEventManager", "onEvent():JSON structure Exception!");
        }
    }

    public void ab(String str, Context context, LinkedHashMap<String, String> linkedHashMap) {
        JSONObject ab = ab((Map) linkedHashMap);
        com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().ab(str, context.getClass().getCanonicalName(), ab);
    }

    public void ab(String str, String str2, LinkedHashMap<String, String> linkedHashMap) {
        com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().ab(str, str2, ab((Map) linkedHashMap));
    }

    public void bc(String str, int i, String str2, LinkedHashMap<String, String> linkedHashMap) {
        String str3 = str;
        int i2 = i;
        String str4 = str2;
        com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().ab(str3, i2, str4, ab((Map) linkedHashMap), System.currentTimeMillis());
    }

    public void bc(String str, Context context) {
        com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().bc(str, context.getClass().getCanonicalName(), new JSONObject());
    }

    public void bc(String str, Context context, LinkedHashMap<String, String> linkedHashMap) {
        com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().bc(str, context.getClass().getCanonicalName(), ab((Map) linkedHashMap));
    }

    public void bc(String str, String str2, LinkedHashMap<String, String> linkedHashMap) {
        com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().bc(str, str2, ab((Map) linkedHashMap));
    }
}
